//
//  checkFunction.cpp
//  class
//
//  Created by Threese on 2019/7/23.
//  Copyright © 2019 Threese. All rights reserved.
//

#include "checkFunction.h"

using namespace std;

ITask* checkToday(IPlan *p){
    ITask *t = new CTask();
    
    IPlan *pPtr = p;
    while (pPtr) {
        IDate *date;
        date = new CDate();
        date->getToday();
        
        ITimeLine *tlPtr = pPtr->getTimeLine(0);
        while (tlPtr) {
            ITask *tPtr = tlPtr->getTask();
            while (tPtr) {
                if(date->compare(date, tPtr->getStartDate()) <= 0
                   && date->compare(date, tPtr->getEndDate()) >= 0){
                    ITask *tTemp = new CTask( );
                    
                    tTemp->setName(tPtr->getName());
                    tTemp->setLabel(tPtr->getLabel());
                    tTemp->setRemarks(tPtr->getRemarks());
                    tTemp->setStartDate(*(tPtr->getStartDate()));
                    tTemp->setEndDate(*(tPtr->getEndDate()));
                    tTemp->setImportance(tPtr->getImportance());
                    
                    t->add(tTemp);
                }
                
                tPtr = const_cast<ITask*>(tPtr->getNext());
            }
            
            tlPtr = const_cast<ITimeLine*>(tlPtr->getNext());
        }
        
        pPtr = const_cast<IPlan*>(pPtr->getNext());
    }
    
    return t;
}
